//
//  WPUserProtocolViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/3/30.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPUserProtocolViewController.h"
#import "WPDetailProtocolViewController.h"

static NSString *const kUITableViewCellIdentifier = @"cellIdentifier";

@interface WPUserProtocolViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView * titlesTableView;/**< 协议表格视图 */
@property (nonatomic, strong) NSArray * titlesArr;/**< 协议标题数组 */
@end

@implementation WPUserProtocolViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}
#pragma mark - init
- (void)initializeDataSource {
    self.titlesArr = @[@[@"风险提示书", @"riskHint.html"],
                       @[@"服务协议", @"serveTreaty.html"],
                       @[@"项目回报承诺", @"return.html"],
                       @[@"项目众筹及交易业务收费细则", @"charge.html"],
                       @[@"项目众筹及交易规则", @"trade.html"],
                       @[@"互联网创新交易中心转让细则", @"trade1.html"]];
}
- (void)initializeUserInterface {
    self.navigationController.navigationBarHidden = NO;
    [self.view addSubview:self.titlesTableView];
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _titlesArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kUITableViewCellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kUITableViewCellIdentifier];
    }
    cell.accessoryType = UITableViewRowActionStyleNormal;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = _titlesArr[indexPath.row][0];
    cell.textLabel.textColor = COLOR_RGB(91, 91, 91, 1);
    cell.textLabel.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
    return cell;
}
#pragma mark - UITableViewDelegate
//用户点击了某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    WPDetailProtocolViewController * detailVC = [[WPDetailProtocolViewController alloc]init];
    detailVC.htmlStr = _titlesArr[indexPath.row][1];
    [self pushToNextController:detailVC withVCTitle:_titlesArr[indexPath.row][0]];
}

#pragma mark - getter
- (UITableView *)titlesTableView {
    if (!_titlesTableView) {
        _titlesTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, SCREEN_SIZE.height - navBar_Fheight) style:UITableViewStylePlain];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.separatorColor = COLOR_RGB(242, 242, 242, 1);
            tableview.backgroundColor = [UIColor clearColor];
            tableview;
        });
    }
    return _titlesTableView;
}

@end
